//
//  DUMenuView.swift
//  SimpleCal
//
//  Created by 杜晓祥 on 2021/11/2.
//

import Cocoa

@IBDesignable
class DUMenuView: NSView {
    private let menus =
        [["manageIcon":"通用设置"],
        ["typeIcon":"节日类型"],
        ["infoIcon":"节日信息"],
        ["dateIcon":"主题设置"],
        ["sortIcon":"状态栏"]]
    
    
    private var menuGroup = RadioGroup<DUMenuButton>()

    override init(frame frameRect: NSRect) {
        super.init(frame: frameRect)
        
        initialize()
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
        initialize()
    }
    
    override func layout() {
        self.layer?.backgroundColor = CGColor(red: 0.97, green: 0.97, blue: 0.97, alpha: 1)
    }
    
    private func initialize () {
        var i:Int = 3
        for menu in menus {
            let m = DUMenuButton(frame: NSRect(x: i, y: 0, width: 56, height: 71))
            m.stringValue(menu.first!.value)
            m.image(menu.first!.key)
            menuGroup.addSubview(view: m)
            self.addSubview(m)
            i += 56
        }
    }
    
    var isEnable:Bool = false {
        didSet {
            menuGroup.isEnable = isEnable
        }
    }
}
